package be.novelfaces.webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;

import be.novelfaces.showcase.webdriver.util.AjaxHelper;

public abstract class BaseElement {

	public BaseElement() {
		PageFactory.initElements(
				new AjaxElementLocatorFactory(WebDriverManager.getWebdriver(),
						15), this);
	}

	private AjaxHelper ajaxHelper = new AjaxHelper();

	protected void waitForAjaxToComplete() {
		ajaxHelper.waitForAjaxToComplete();
	}

	protected WebDriver getWebDriver() {
		return WebDriverManager.getWebdriver();
	}

	protected boolean isElementPresent(By selector) {
		try {
			getWebDriver().findElement(selector);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}

}